/***
@文件名：authopen_config.js
@来源：Winford.Wang|2021-12-06，17:51
@描述：开机自启设置
***/
import { app, ipcMain} from 'electron'
import PARAME from '@/complete/param/parameterList'

const exePath = process.execPath;
// 设置开机自启
const setAuthOpen = function() {
  ipcMain.on(PARAME.SETAUTOSTART_MAIN_APP, () => {
    app.setLoginItemSettings({
      openAtLogin: true,
      path: exePath,
      args: []
    })
  });
}
// 移除开机自启
const removeAuthOpen = function() {
  ipcMain.on(PARAME.DELAUTOSTART_MAIN_APP, () => {
    app.setLoginItemSettings({
      openAtLogin: false,
      path: exePath,
      args: []
    })
  })
}
// 获取开机自启
const getAuthOpen = function(win) {
  ipcMain.on(PARAME.GETAUTOSTART_MAIN_APP, () => {
    win.webContents.send(PARAME.GETAUTOSTARTINFO_MAIN_APP, app.getLoginItemSettings())
  })
}

export {
  setAuthOpen, removeAuthOpen, getAuthOpen
}
